<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\ProjectInvestigation;

/**
 * ProjectInvestigationSearch represents the model behind the search form about `common\models\ProjectInvestigation`.
 */
class ProjectInvestigationSearch extends ProjectInvestigation
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'project_id', 'lock_user'], 'integer'],
            [['borrower', 'guarantor', 'mortgagor', 'mortgage_type', 'principal', 'interest', 'lawsuit', 'execution', 'auction', 'records_investigation', 'records_consistence', 'order_sent', 'execution_method', 'layer_interview', 'debt_collection', 'prescription', 'origin_files', 'conclusion', 'created_at', 'updated_at', 'lock_timestamp'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ProjectInvestigation::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'project_id' => $this->project_id,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'lock_user' => $this->lock_user,
        ]);

        $query->andFilterWhere(['like', 'borrower', $this->borrower])
            ->andFilterWhere(['like', 'guarantor', $this->guarantor])
            ->andFilterWhere(['like', 'mortgagor', $this->mortgagor])
            ->andFilterWhere(['like', 'mortgage_type', $this->mortgage_type])
            ->andFilterWhere(['like', 'principal', $this->principal])
            ->andFilterWhere(['like', 'interest', $this->interest])
            ->andFilterWhere(['like', 'lawsuit', $this->lawsuit])
            ->andFilterWhere(['like', 'execution', $this->execution])
            ->andFilterWhere(['like', 'auction', $this->auction])
            ->andFilterWhere(['like', 'records_investigation', $this->records_investigation])
            ->andFilterWhere(['like', 'records_consistence', $this->records_consistence])
            ->andFilterWhere(['like', 'order_sent', $this->order_sent])
            ->andFilterWhere(['like', 'execution_method', $this->execution_method])
            ->andFilterWhere(['like', 'layer_interview', $this->layer_interview])
            ->andFilterWhere(['like', 'debt_collection', $this->debt_collection])
            ->andFilterWhere(['like', 'prescription', $this->prescription])
            ->andFilterWhere(['like', 'origin_files', $this->origin_files])
            ->andFilterWhere(['like', 'conclusion', $this->conclusion])
            ->andFilterWhere(['like', 'lock_timestamp', $this->lock_timestamp]);

        return $dataProvider;
    }
}
